//thanks to http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.1
//for this wonderful piece of code

#include <sstream>
#include <stdexcept>

class BadConversion : public std::runtime_error {
public:
BadConversion(const std::string& s)
 : std::runtime_error(s)
 { }
};

inline std::string stringify(double x)
{
std::ostringstream o;
if (!(o << x))
 throw BadConversion("stringify(double)");
return o.str();
}